﻿namespace ufida.u9.ait.openapi
{
	using System;
	using System.Collections.Generic;
	using System.Text;
    using ufida.u9.ait.openapi.utils;
    using UFIDA.U9.Base;
    using UFIDA.U9.CBO.HR.Operator;
    using UFIDA.U9.ISV.DeptOperatorSV;
    using UFIDA.U9.ISV.DeptOperatorSV.Proxy;
    using UFSoft.UBF.AopFrame;	
	using UFSoft.UBF.Util.Context;

	/// <summary>
	/// OperatorSave partial 
	/// </summary>	
	public partial class OperatorSave 
	{	
		internal BaseStrategy Select()
		{
			return new OperatorSaveImpementStrategy();	
		}		
	}
	
	#region  implement strategy	
	/// <summary>
	/// Impement Implement
	/// 
	/// </summary>	
	internal partial class OperatorSaveImpementStrategy : BaseStrategy
	{
		public OperatorSaveImpementStrategy() { }

		public override object Do(object obj)
		{						
			OperatorSave bpObj = (OperatorSave)obj;

			//try
			//{
			//	if (bpObj.Data == null || bpObj.Data.Count == 0)
			//		throw new Exception("传入参数为空");

			//	List<OperatorsData> retlist = new List<OperatorsData>();
			//	List<object> inputdtos = DTOUtils.DTOListPropCopy(bpObj.Data.ConvertAll(item => item as object)
			//		, typeof(CopyOfCopyOfOperatorsDTOData));
			//	foreach (CopyOfCopyOfOperatorsDTOData dto in inputdtos)
			//	{
			//		Operators item = Operators.Finder.Find($"Code='{dto.Code}' and Org={Context.LoginOrg.ID}");
			//		dto.Org = new UFIDA.U9.CBO.Pub.Controller.CommonArchiveDataDTOData
			//		{
			//			ID = Context.LoginOrg.ID,
			//			Code = Context.LoginOrg.Code,
			//		};

			//		if (item == null)
			//		{
			//			//新增逻辑
			//			//设置默认值
			//			if (dto.OperatorLine == null || dto.OperatorLine.Count == 0)
			//			{
			//				CopyOfCopyOfOperatorLineDTOData data0 = new CopyOfCopyOfOperatorLineDTOData();
			//				data0.OperatorType = 0;//采购业务员
			//				CopyOfCopyOfOperatorLineDTOData data1 = new CopyOfCopyOfOperatorLineDTOData();
			//				data1.OperatorType = 1;//销售业务员
			//				CopyOfCopyOfOperatorLineDTOData data2 = new CopyOfCopyOfOperatorLineDTOData();
			//				data2.OperatorType = 2;//库管员
			//                         CopyOfCopyOfOperatorLineDTOData data3 = new CopyOfCopyOfOperatorLineDTOData();
			//                         data2.OperatorType = 13;//其他
			//                         dto.OperatorLine = new List<CopyOfCopyOfOperatorLineDTOData>() { data0, data1,data2,data3 };
			//			}

			//			BatchCreateOperatorByDTOSVProxy proxy = new BatchCreateOperatorByDTOSVProxy();
			//			proxy.Operators=new List<CopyOfCopyOfOperatorsDTOData> { dto };
			//                     List<OperatorsData> ret = proxy.Do();
			//			if (ret.Count > 0)
			//				retlist.Add(ret[0]);
			//		}
			//		else
			//		{
			//			//修改逻辑
			//			BatchModifyOperatorByDTOSVProxy proxy = new BatchModifyOperatorByDTOSVProxy();
			//			proxy.Operators = new List<CopyOfCopyOfOperatorsDTOData> { dto};
			//                     List<OperatorsData> ret = proxy.Do();
			//			if (ret.Count > 0)
			//				retlist.Add(ret[0]);
			//		}
			//	}
			//	return ResultUtils.success(bpObj, bpObj.Data, retlist);
			//}
			//catch (Exception ex)
			//{
			//	return ResultUtils.error(bpObj, bpObj.Data, ex);
			//}

			return CodeUtils.EntitySave(bpObj, bpObj.Data, OperatorBase.CreateDoc, OperatorBase.UpdateDoc);
		}
	}		

	#endregion
	
	
}